Component({
  properties: {
    targetValue: {
      type: Number,
      value: 0,
      observer: 'startRolling'
    },
    duration: {
      type: Number,
      value: 2000
    }
  },
  
  data: {
    currentValue: 0
  },

  methods: {
    startRolling() {
      const { targetValue, duration } = this.data;
      const steps = 100; // 滚动的步数
      const intervalTime = duration / steps; // 每步的时间
      const increment = Math.ceil(targetValue / steps); // 每步增加的值

      let currentValue = 0;
      const interval = setInterval(() => {
        currentValue += increment;
        if (currentValue >= targetValue) {
          currentValue = targetValue; // 确保不超过目标值
          clearInterval(interval); // 清除定时器
        }
        this.setData({ currentValue });
      }, intervalTime);
    }
  }
});
